//////////////////////////////////////////////////////////////////////////////
//
//  Created by Philip Mulcahy on 30/01/2012.
//  Copyright (c) 2012 Philip Mulcahy. All rights reserved.
//
//  This file is part of the note-recog library.
//
//  note-recog is free software: you can redistribute it and/or modify
//  it under the terms of version 3 of the GNU Lesser General Public License 
//  as published by the Free Software Foundation.
//
//  note-recog is distributed is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with note-recog.  If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef note_recog_Slice_h
#define note_recog_Slice_h

#include <iostream>
#include <vector>
#include <memory>
#include "Log.h"
#include "Spectrum.h"

class Harmonic;

class Slice
{
public:
    typedef std::vector<float>::const_iterator fft_iterator; 
    
private:
    LOG_DECLARE;
    const Spectrum _spec;
    const float _binWidthHz;
    const size_t _fftLength;
    const size_t _binCount;
    const size_t _startFrameNumber;
    const double _startSeconds;
    float _rmsLevel;
    std::shared_ptr<const Harmonic> _dominant;
    std::shared_ptr<const Harmonic> _fundamental;
    const std::vector<short> _timeDomain;
    
public:
    Slice(
          size_t startFrameNumber,
          double startSeconds,
          const Spectrum& spec,
          const std::vector<short>& timeDomain
    );
    
    const float& binWidthHz() const {     return _binWidthHz; }
    const float& rmsLevel() const {       return _rmsLevel; }
    const Harmonic& dominant()  const {   return *_dominant; }
    const Harmonic& fundamental() const { return *_fundamental; }
    size_t binCount() const { return _binCount; };
    bool isGood() const;
    double startSeconds() const { return _startSeconds; }
    size_t startFrameNumber() const {  return _startFrameNumber; }
    const Spectrum& spectrum() const { return _spec; }
    const std::vector<short>& timeDomain() const { return _timeDomain; }
};

std::ostream& operator<<( std::ostream& os, const Slice& slice );

#endif
